package com.gitee.feizns.web.ex.impl;

import com.gitee.feizns.web.domain.result.Ret;
import com.gitee.feizns.web.ex.CustomizeExceptionHandler;
import com.gitee.feizns.web.ex.GlobalRestfulExceptionAdvice;
import com.gitee.feizns.web.ex.MessageException;
import org.springframework.http.ResponseEntity;

/**
 * @author feizns
 * @since 2019/8/3 0003
 */
public class MessageExceptionHandler implements CustomizeExceptionHandler<MessageException, Object> {

    @Override
    public ResponseEntity<Ret<Object>> handle(MessageException e) {

        ResponseEntity ret = GlobalRestfulExceptionAdvice.errorMappingHandle(e);
        if ( ret != null )
            return ret;

        if ( e.getMessage() != null )
            return ResponseEntity.ok(Ret.err(e.getMessage()));

        return ResponseEntity.ok(Ret.err(CustomizeExceptionHandler.defaultMsg(e)));
    }

}
